package com.skycode6.servlet;

import com.skycode6.bean.NoticeBean;
import com.skycode6.dao.NoticeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/noticeEdit.jsp")
public class NoticeEditServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        String User = (String) session.getAttribute("user");
        if (User == null || User.equals("")) {
            resp.sendRedirect("login.jsp");
            return;
        }
        req.setCharacterEncoding("UTF-8");
        NoticeBean noticeBean = new NoticeBean();
        int noticeId = Integer.parseInt(req.getParameter("noticeId"));
        @@ -22,7 +29,7 @@ public class NoticeEditServlet extends HttpServlet {
        noticeBean.setNoticeID(noticeId);
        noticeBean.setNoticeTitle(title);
        noticeBean.setNoticeContent(content);
        noticeBean.setAdminName("admin");//todo更换为登陆的管理员名称
        noticeBean.setAdminName(User);//更换为登陆的管理员名称
            //添加
            NoticeDao noticeDao = new NoticeDao();
            int result = noticeDao.update(noticeBean);//返回受影响的行